package org.nightrunner.d3.service.impl;

import java.io.Serializable;
import java.util.List;

import org.nightrunner.d3.dao.IReferenceDao;
import org.nightrunner.d3.entity.Reference;
import org.nightrunner.d3.model.DefaultPaginationInfo;
import org.nightrunner.d3.model.IPaginationInfo;
import org.nightrunner.d3.model.PaginationModel;
import org.nightrunner.d3.service.IReferenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Reference Service implementation
 * 
 * @author NigthRunner
 * @date 2012-7-26
 * @version 1.0
 */

@Service
public class ReferenceService implements IReferenceService {

	@Autowired
	private IReferenceDao referenceDao;

	public IReferenceDao getReferenceDao() {
		return referenceDao;
	}

	public void setReferenceDao(IReferenceDao referenceDao) {
		this.referenceDao = referenceDao;
	}

	public Serializable addReference(Reference reference) {
		return referenceDao.save(reference);
	}

	public Reference getReference(String bureauId) {
		return referenceDao.get(bureauId);
	}

	public List<Reference> getAllReference() {
		return referenceDao.list();
	}

	public void deleteReference(Reference reference) {
		referenceDao.delete(reference);
	}

	public PaginationModel<List<Reference>> getReferences() {
		IPaginationInfo paginationInfo = new DefaultPaginationInfo();
		paginationInfo.setCurrentPage(0);
		paginationInfo.setRowSize(10);
		return getReferences(paginationInfo);
	}

	public PaginationModel<List<Reference>> getReferences(
			IPaginationInfo pagination) {
		return referenceDao.find(pagination);
	}

	public void updateReference(Reference reference) {
		referenceDao.merge(reference);
	}

}
